package hn.cch.spring.boot.service.impl;

import hn.cch.spring.boot.constant.HttpConstant;
import hn.cch.spring.boot.service.CookieService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

@Service
public class CookieServiceImpl implements CookieService {

    private final static Logger logger = LoggerFactory.getLogger(CookieServiceImpl.class);


    public void createCookie(HttpServletResponse httpServletResponse){
        String string = UUID.randomUUID().toString();
        logger.info("cookie:{}", string);
        Cookie cookie = new Cookie(HttpConstant.TOKEN, string);
        cookie.setDomain("localhost");
        cookie.setPath("/");
        cookie.setMaxAge(10);
        cookie.setHttpOnly(true);
        cookie.setSecure(false);
        httpServletResponse.addCookie(cookie);
    }

}
